/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.caelum.dao;

import br.com.caelum.model.Grupo;
import br.com.caelum.model.Permissao;
import br.com.caelum.util.HibernateUtil;
import br.com.caelum.vraptor.ioc.Component;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author estagiario
 */
@Component
public class PermissaoDao extends GenericDao<Permissao> {

    @Override
    protected Class<Permissao> getClassePersistente() {
        return Permissao.class;
    }
    
    public List buscarPorIdGrupo(int idGrupo, int idRecurso) {
        Session sessao = HibernateUtil.getSessionFactory().getCurrentSession();
        sessao.beginTransaction();
        Query query = sessao.createQuery("from Permissao as p where (p.grupo = :id_grupo) and (p.recurso = :id_recurso)");
        query.setInteger("id_grupo", idGrupo);
        query.setInteger("id_recurso", idRecurso);
        List list = query.list();
        sessao.getTransaction().commit();
        return list;
    }
    
}
